<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class smsAction extends sfActions{
    public function execute(){
        $this->page = $this->getRequestParameter('page', 1);
        $this->phoneNumber = trim($this->getRequestParameter('phone_number', ""));
        if($this->phoneNumber != ""){$this->phoneNumber = iringback::checkPhoneNumber($this->phoneNumber)->phone;}
        $this->smsType = trim($this->getRequestParameter('sms_type', "Ra"));
        $this->createdDatetimeFrom = $this->getRequestParameter('created_datetime_from', "");
        $this->createdDatetimeTo = $this->getRequestParameter('created_datetime_to', "");
        $createdDatetimeFrom = strtotime($this->createdDatetimeFrom);
        $createdDatetimeTo = strtotime($this->createdDatetimeTo);
        $limit = sfConfig::get('customer_care_limit');
        $offset = ($this->page-1)*$limit;
        $c = new Criteria();
        $c->setLimit($limit);
        $this->sms = null;
        if($this->smsType == 'Ra'){
            $this->sms = SmsOutputPeer::getSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo, $limit, $offset);
            $this->totalSms = SmsOutputPeer::getTotalSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo);
        }elseif($this->smsType == 'Vào'){
            $this->sms = SmsInputPeer::getSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo, $limit, $offset);
            $this->totalSms = SmsInputPeer::getTotalSms($this->phoneNumber, $createdDatetimeFrom, $createdDatetimeTo);
        }
        $this->totalPage = intval($this->totalSms/$limit);
        if($this->totalPage%$limit > 0){
            $this->totalPage = $this->totalPage +1;
        }
    }
}
?>
